import React, {useEffect, useState} from "react";
import Taro from "@tarojs/taro"
import {View} from "@tarojs/components";
import userStore from "../store/userStore";

export default function (Widget) {
  return () => {
    const [show,setShow] = useState(false);
    const userInfo = userStore.useStore(state => state.value)
    useEffect(()=>{
      console.log(userInfo);
        if(userInfo?.isLogin){
          setShow(true)
        }else{
          Taro.redirectTo({
            url:"/pages/login/index"
          })
        }
    },[userInfo])
    if(!show) return <View></View>
    return (<Widget />)
  }
}
